package com.supplychain.scm.core.rocketmq.storage;

import com.supplychain.scm.core.rocketmq.bean.BaseMessageConsumer;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Executor;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName IMqMessageConsumerStorage
 * @Description 消费者消费消息记录
 * @createTime 13:20:00 2023/03/14
 */
public interface IMqMessageConsumerStorage {

    boolean createBaseMessageConsumer(BaseMessageConsumer baseMessageConsumer);

    default void createBaseMessageConsumer(BaseMessageConsumer baseMessageConsumer, Executor executor) {
        Boolean ifStore = Optional.ofNullable(baseMessageConsumer).map(BaseMessageConsumer::getIfStore).orElse(Boolean.TRUE);
        if(ifStore) {
            if(Objects.nonNull(executor)) {
                executor.execute(()-> createBaseMessageConsumer(baseMessageConsumer));
            } else {
                createBaseMessageConsumer(baseMessageConsumer);
            }
        }
    }
}
